package com.atom.zx;

import com.atom.zx.operators.OperationAll;
import com.atom.zx.util.Logs;
import com.atom.zx.util.functions.Func1;

import java.util.concurrent.atomic.AtomicBoolean;


public class MainTest {

    public static final void main(String[] aa) {
        MainTest test = new MainTest();
        //test.test_base();
        test.test_atom_boolean();
        OperationAll.UnitTest testOperationAll = new OperationAll.UnitTest() ;
        //testOperationAll.main_testAll();
    }

    public void test_base() {
        Observable<String> asdasd = Observable.create(new Func1<Observer<String>, Subscription>() {
            @Override
            public Subscription call(Observer<String> stringObserver) {
                //stringObserver.onCompleted();
                stringObserver.onNext("asdasd");
                //stringObserver.onError(new Exception("create Error"));
                stringObserver.onCompleted();
                return new Subscription() {
                    @Override
                    public void unsubscribe() {

                    }
                };
            }
        });
        Observer<String> observer = new Observer<String>() {
            @Override
            public void onCompleted() {
                System.out.println("onCompleted");
            }

            @Override
            public void onError(Throwable e) {
                System.out.println("onError" + e.getLocalizedMessage());
            }

            @Override
            public void onNext(String args) {
                System.out.println("onNext -> " + args);
            }
        };
        Subscription subscribe = asdasd.subscribe(observer);
    }

    public void test_atom_boolean(){
        final AtomicBoolean status = new AtomicBoolean(true);
        boolean b1 = status.get();
        boolean andSet = status.getAndSet(false);
        b1 = status.get();
        b1 = status.compareAndSet(false, true);
        b1 = status.get();
    }
}
